Imports System.Data
Imports BlazeApps.Library.Events

Partial Class Usercontrols_Event_Events
    Inherits UserControlBase

#Region " Enums, Memebers and Properties "


#End Region

#Region " Page Events "

    Protected Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
        Me.MessageLabel = Me.uxMessagesLabel
    End Sub

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        SetPageTitle("Events")

        LoadSettings()

        Me.uxAddEventPanel.Visible = ((IsUserAuthenticated And EnableUserEvents) OrElse IsEventModerator())

    End Sub

#End Region

#Region " Save Data "


#End Region

#Region " Load Data "
    Private Sub LoadSettings()
        MostRecentPanel.Visible = DisplayLatestEvents
        MostViewedPanel.Visible = DisplayMostViewedBlogs
        MostCommentsPanel.Visible = DisplayMostCommentsBlogs
        HighestRankedPanel.Visible = DisplayHighestRankedBlogs

        MostRecentPanel.Enabled = DisplayLatestEvents
        MostViewedPanel.Enabled = DisplayMostViewedBlogs
        MostCommentsPanel.Enabled = DisplayMostCommentsBlogs
        HighestRankedPanel.Enabled = DisplayHighestRankedBlogs
    End Sub
#End Region

#Region " Form Controls Events "

    Protected Sub uxAddEventButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles uxAddEventButton.Click
        Response.Redirect("~/events.aspx?pid=eve_addevent")
    End Sub

    Protected Sub uxEventsCalendar_DayRender(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DayRenderEventArgs) Handles uxEventsCalendar.DayRender
        Dim List As New EventList

        Dim ds As DataSet = List.GetEvents()

        Dim s As String = e.Day.Date.ToShortDateString

        e.Cell.Text = e.Day.Date.Day.ToString + "<BR>"

        Dim l As LiteralControl = New LiteralControl
        l.Text = e.Day.Date.Day.ToString + "<BR>"
        e.Cell.Controls.Add(l)

        For Each row As DataRow In ds.Tables(0).Rows
            Dim scheduledDate As String = Convert.ToDateTime(row("eventdate")).ToShortDateString

            If scheduledDate.Equals(s) Then

                Dim lb As LinkButton = New LinkButton
                lb.Text = String.Format("<a href='{0}.aspx?pid=eve_eventviewer&id={1}'>{2}</a><br />", AppPage, row("eventid").ToString.Trim, row("eventtitle").ToString.Trim)
                e.Cell.Controls.Add(lb)

            End If

        Next

    End Sub

#End Region

#Region " Helpers and Methods "


#End Region

End Class
